<?php 
header("content-type:text/html;charset=utf-8");
$db=new PDO("mysql:host=127.0.0.1;dbname=zice;charset=utf8",'root','root');
$city=$_POST['city'];
$dbsql="select * from tian where city='$city'";
$res=$db->query($dbsql)->fetchAll(PDO::FETCH_ASSOC);
if(!$res){
	$url="http://www.phpstudy.net/jiekou.php?city=$city";
	$data=file_get_contents($url);
	$data=json_decode($data,true);
	// print_r($data);die;
	$res=$data['result'];
	// print_r($res);die;
	foreach ($res as $value) {
		$city=$value['citynm'];
		$week=$value['week'];
		$high=$value['temp_high'];
		$low=$value['temp_low'];
		$tianqi=$value['temperature'];
		$sql="insert into tian values  ('','$city','$week','$high','$low','$tianqi')";
		$db->exec($sql);
	}
}

echo json_encode($res);











 ?>